package Thread.ReadWriteDemo;

import JavaSe.Obj;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}21:34
 */

class MyCache{
    private volatile Map<String,Object> map = new HashMap<>();
//    private Lock lock = new ReentrantLock();//不加任何锁
    private ReentrantReadWriteLock rwlock = new ReentrantReadWriteLock();

    //读
    public void put(String key, Object value){
        rwlock.writeLock().lock();
        System.out.println(Thread.currentThread().getName() +"\t 正在写入："+key);
        map.put(key,value);
        System.out.println(Thread.currentThread().getName() + "\t正在写入："+key);
    }

    //写


    //清空
}

public class ReadWriteDemo {

}
